#include <drogon/HttpController.h>
#include "services/StorageFuncService.h"
#include "utils/Defs.h"

using namespace drogon;

SNB_API_BEGIN

// 定义 always_false 模板（放在类外部）
template <typename T>
constexpr bool always_false = false;

class StorageFuncCtr : public drogon::HttpController<StorageFuncCtr>
{
public:
    // 处理函数声明
    void handleHelloWorld(
        const HttpRequestPtr& req,
        std::function<void(const HttpResponsePtr&)>&& callback);
    
    void handleGetAllDiskInfo(
        const HttpRequestPtr& req,
        std::function<void(const HttpResponsePtr&)>&& callback);
    
    void handleGetAllDiskNames(
        const HttpRequestPtr& req,
        std::function<void(const HttpResponsePtr&)>&& callback);
    
    void handleGetAllDiskUuids(
        const HttpRequestPtr& req,
        std::function<void(const HttpResponsePtr&)>&& callback);
    
    void handleGetDiskInfoByUuid(
        const HttpRequestPtr& req,
        std::function<void(const HttpResponsePtr&)>&& callback,
        const std::string& uuid);  // 添加路径参数
    
    void handleGetDiskStateByUuid(
        const HttpRequestPtr& req,
        std::function<void(const HttpResponsePtr&)>&& callback,
        const std::string& uuid);  // 添加路径参数

    METHOD_LIST_BEGIN
        METHOD_ADD(StorageFuncCtr::handleHelloWorld, "/helloworld", Get);
        METHOD_ADD(StorageFuncCtr::handleGetAllDiskInfo, "/disk_info_all", Get);
        METHOD_ADD(StorageFuncCtr::handleGetAllDiskNames, "/disk_names_all", Get);
        METHOD_ADD(StorageFuncCtr::handleGetAllDiskUuids, "/disk_uuids_all", Get);
        METHOD_ADD(StorageFuncCtr::handleGetDiskInfoByUuid, "/disk_info_by_uuid/{uuid}", Get);
        METHOD_ADD(StorageFuncCtr::handleGetDiskStateByUuid, "/disk_state_by_uuid/{uuid}", Get);
    METHOD_LIST_END

private:
    template <typename T>
    HttpResponsePtr createApiResponse(T&& result);

    std::shared_ptr<snb::srv::StorageFuncService> m_storageService = 
        std::make_shared<snb::srv::StorageFuncService>();
};

SNB_API_END